<div class="row">
	<div class="box col-md-12">
		<div class="box-inner">
			<div class="box-header well">
				<h2><i class="glyphicon glyphicon-user"></i> Danh sách sản phẩm</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
					<a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
				</div>
			</div>
			<div class="box-content"><?php
				echo form_open_multipart(null,array('class'=>'form-horizontal','id'=>'formUpload'));
				?><div class="control-group"><?php
					echo form_upload(array(
						'name' => 'userfile','value'=>'',
						'id'=>'imgFile','multiple'=>'multiple',
						'accept'=>'image/*'
					));
					echo form_hidden(array(
						'name'=>'ajax','value'=>0,'id'=>'ajax'
					));
				?></div><noscript><?php
					echo form_submit('submit','Upload');
				 ?></noscript><?php
				 echo form_close();
				?>
				<div class="row">
					<div class="col-md-6 col-md-offset-3" id="uploadControl" style="display:none">
						<button class="btn btn-primary" id="uploadStart" onclick="$('#imgFile').uploadify('upload','*');">Upload</button> 
						<button class="btn btn-danger" id="uploadStop" onclick="$('#imgFile').uploadify('stop');">Stop</button>
					</div>
				</div><div class="row">
					<div class="col-md-6 col-md-offset-3" id="imageInfo"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(function(){
	<?php $timestamp = time(); ?>
	$('#imgFile').uploadify({
		'formData'     : {
			'timestamp' : '<?php echo $timestamp;?>',
			'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                        'cookie_data': '<?php echo $this->session->cookie_data; ?>'
		},
		'fileObjName':'userfile','fileTypeDesc':'jpg','auto':false,'removeCompleted':false,'uploadLimit':60,
		'queueID':'imageInfo','cancelImg':'<?php echo base_url(); ?>assets/images/uploadify-cancel.png',
		'swf'      : '<?php echo base_url(); ?>assets/js/uploadify/uploadify.swf',
		'uploader' : '<?php echo base_url(); ?>admin/gallery/uploadAjax',
		'fileTypeExts'     : '*.jpg;*.gif;*.png;*.jpeg;',
	    'onUploadSuccess' : function(file, data, response) {
			console.log(data);
			console.log(file);
	    	data = $.parseJSON(data);
			if(data.status == 'success'){
				$('#'+file.id).empty().append('<div class="media col-md-12 text-left"><a href="#'+file.id+'" class="pull-left col-md-3"><img class="media-object thumbnail" src="'+data.thumb+'"/></a><div class="media-body controls col-md-8" style="padding-top:33px"><input type="text" class="thumb_input col-md-12 form-control" value="'+data.img+'" disabled /></div></div>');
			}
			else if(data.status == 'error'){
				console.log(data.msg);
				$('#'+file.id).find('span.data').text(' - Error {'+data.msg+'}').end().css('backgroundColor','#f2dede');
			}
	    },
	    'onSelect' : function(){
	    	$('#uploadControl').fadeIn('slow');
	    }
	});
	$('#ajax').val(1);
	$('#imageInfo').on('click','.media a',function(){
		$(this).siblings('div').find('input').select();
	});
});
</script>